<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qqmllist.cpp -->
  <title>QQmlListReference  类 | Qt QML 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtqml-index.html">Qt QML</a></td><td ><a href="qtqml-module.html">
			C++ <span lang="zh-cn">类</span></a></td><td >QQmlListReference</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtqml-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#public-functions">公用函数</a></li>
<li class="level1"><a href="#details">详细信息</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QQmlListReference <span lang="zh-cn">类</span></h1>
<!-- $$$QQmlListReference-brief -->
<p><a href="qqmllistreference.html">QQmlListReference</a>类允许对<a href="qqmllistproperty.html">QQmlListProperty</a>属性进行操作。 <a href="#details">更多...</a></p>
<!-- @@@QQmlListReference -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> 头文件：</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QQmlListReference&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake<span lang="zh-cn">：</span></td><td class="memItemRight bottomAlign"> QT += qml</td></tr><tr><td class="memItemLeft rightAlign topAlign"> 
	<span lang="zh-cn">自从：</span></td><td class="memItemRight bottomAlign">  Qt 5.0</td></tr></table></div><ul>
<li><a href="qqmllistreference-members.html"></a></li>
</ul>
<a name="public-functions"></a>
<h2 id="public-functions">公用函数</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#QQmlListReference">QQmlListReference</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#QQmlListReference-1">QQmlListReference</a></b>(QObject *<i>object</i>, const char *<i>property</i>, QQmlEngine *<i>engine</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#append">append</a></b>(QObject *<i>object</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QObject *</td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#at">at</a></b>(int <i>index</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#canAppend">canAppend</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#canAt">canAt</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#canClear">canClear</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#canCount">canCount</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#clear">clear</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#count">count</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#isManipulable">isManipulable</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#isReadable">isReadable</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#isValid">isValid</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const QMetaObject *</td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#listElementType">listElementType</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QObject *</td><td class="memItemRight bottomAlign"><b><a href="qqmllistreference.html#object">object</a></b>() const</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QQmlListReference-description -->
<div class="descr">
<h2 id="details">详细信息</h2>
<p><a href="qqmllistreference.html">QQmlListReference</a>类允许对<a href="qqmllistproperty.html">QQmlListProperty</a>属性进行操作。</p>
<p><a href="qqmllistreference.html">QQmlListReference</a>允许C++程序以简单和类型安全的方式读取QML列表属性，并为其赋值。<a href="qqmllistreference.html">QQmlListReference</a>可以通过传递对象和属性名或通过<a href="qqmlproperty.html">QQmlProperty</a>实例创建。这两个是等价的:</p>
<pre class="cpp">

  <span class="type"><a href="qqmllistreference.html#QQmlListReference">QQmlListReference</a></span> ref1(object<span class="operator">,</span> <span class="string">&quot;children&quot;</span>);

  <span class="type"><a href="qqmlproperty.html">QQmlProperty</a></span> ref2(object<span class="operator">,</span> <span class="string">&quot;children&quot;</span>);
  <span class="type"><a href="qqmllistreference.html#QQmlListReference">QQmlListReference</a></span> ref2 <span class="operator">=</span> qvariant_cast<span class="operator">&lt;</span><span class="type"><a href="qqmllistreference.html#QQmlListReference">QQmlListReference</a></span><span class="operator">&gt;</span>(ref2<span class="operator">.</span>read());

</pre>
<p>不是所有的QML列表属性都支持所有的操作。<a href="qqmllistreference.html#canAppend">canAppend</a>()、<a href="qqmllistreference.html#canAt">canAt</a>()、<a href="qqmllistreference.html#canClear">canClear</a>()和<a href="qqmllistreference.html#canCount">canCount</a>()等一组方法允许程序查询给定属性是否支持某个操作。</p>
<p>QML列表属性是类型安全的。只有派生自正确基类的<a href="../qtcore/qobject.html">QObject</a>才能被赋值给列表。<a href="qqmllistreference.html#listElementType">listElementType</a>()方法可用于查询所支持的<a href="../qtcore/qobject.html">QObject</a>类型的<a href="../qtcore/qmetaobject.html">QMetaObject</a>。试图将不正确类型的对象添加到列表属性将会失败。</p>
<p>与普通列表一样，当通过索引访问列表元素时，调用者有责任确保在调用<a href="qqmllistreference.html#at">at</a>()之前不会使用<a href="qqmllistreference.html#count">count</a>()方法请求超出范围的元素。</p>
</div>
<!-- @@@QQmlListReference -->
<div class="func">
<h2><span lang="zh-cn">成员函数文档</span></h2>
<!-- $$$QQmlListReference[overload1]$$$QQmlListReference -->
<h3 class="fn" id="QQmlListReference"><a name="QQmlListReference"></a>QQmlListReference::<span class="name">QQmlListReference</span>()</h3>
<p>构造无效的实例。</p>
<!-- @@@QQmlListReference -->
<!-- $$$QQmlListReference$$$QQmlListReferenceQObject*constchar*QQmlEngine* -->
<h3 class="fn" id="QQmlListReference-1"><a name="QQmlListReference-1"></a>QQmlListReference::<span class="name">QQmlListReference</span>(<span class="type"><a href="../qtcore/qobject.html">QObject</a></span> *<i>object</i>, const <span class="type">char</span> *<i>property</i>, <span class="type"><a href="qqmlengine.html">QQmlEngine</a></span> *<i>engine</i> = nullptr)</h3>
<p>为<i>object<span lang="zh-cn">（</span></i>对象<span lang="zh-cn">）</span>的<i>property<span lang="zh-cn">（</span></i>属性<span lang="zh-cn">）</span>构造一个<a href="qqmllistreference.html">QQmlListReference</a>。如果属性不是列表属性，则创建一个无效的<a href="qqmllistreference.html">QQmlListReference</a>。如果对象在引用构造之后被销毁，它将自动失效。也就是说，即使在对象被删除之后，也可以安全地保存<a href="qqmllistreference.html">QQmlListReference</a>实例。</p>
<p>访问一些QML创建的列表属性需要传递<i>engine</i> <span lang="zh-cn">（</span>引擎<span lang="zh-cn">）</span>。如果有疑问，引擎是可用的，通过它。</p>
<!-- @@@QQmlListReference -->
<!-- $$$append[overload1]$$$appendQObject* -->
<h3 class="fn" id="append"><a name="append"></a><span class="type">bool</span> QQmlListReference::<span class="name">append</span>(<span class="type"><a href="../qtcore/qobject.html">QObject</a></span> *<i>object</i>) const</h3>
<p>将<i>object</i> <span lang="zh-cn">（</span>对象<span lang="zh-cn">）</span>追加到列表。如果操作成功则返回true，否则返回false。</p>
<p><b>请参考 </b><a href="qqmllistreference.html#canAppend">canAppend</a>()<span lang="zh-cn">。</span></p>
<!-- @@@append -->
<!-- $$$at[overload1]$$$atint -->
<h3 class="fn" id="at"><a name="at"></a><span class="type"><a href="../qtcore/qobject.html">QObject</a></span> *QQmlListReference::<span class="name">at</span>(<span class="type">int</span> <i>index</i>) const</h3>
<p>返回<i>index</i>处的列表元素，如果操作失败则返回0。</p>
<p><b>请参考 </b><a href="qqmllistreference.html#canAt">canAt</a>()<span lang="zh-cn">。</span></p>
<!-- @@@at -->
<!-- $$$canAppend[overload1]$$$canAppend -->
<h3 class="fn" id="canAppend"><a name="canAppend"></a><span class="type">bool</span> QQmlListReference::<span class="name">canAppend</span>() const</h3>
<p>如果列表属性可以被附加到，则返回true，否则返回false。如果引用无效则返回false。</p>
<p><b>请参考 </b><a href="qqmllistreference.html#append">append</a>()<span lang="zh-cn">。</span></p>
<!-- @@@canAppend -->
<!-- $$$canAt[overload1]$$$canAt -->
<h3 class="fn" id="canAt"><a name="canAt"></a><span class="type">bool</span> QQmlListReference::<span class="name">canAt</span>() const</h3>
<p>如果列表属性可以按索引查询，则返回true，否则返回false。如果引用无效则返回false。</p>
<p><b>请参考 </b><a href="qqmllistreference.html#at">at</a>()<span lang="zh-cn">。</span></p>
<!-- @@@canAt -->
<!-- $$$canClear[overload1]$$$canClear -->
<h3 class="fn" id="canClear"><a name="canClear"></a><span class="type">bool</span> QQmlListReference::<span class="name">canClear</span>() const</h3>
<p>如果列表属性可以被清除，则返回true，否则返回false。如果引用无效则返回false。</p>
<p><b>请参考 </b><a href="qqmllistreference.html#clear">clear</a>()<span lang="zh-cn">。</span></p>
<!-- @@@canClear -->
<!-- $$$canCount[overload1]$$$canCount -->
<h3 class="fn" id="canCount"><a name="canCount"></a><span class="type">bool</span> QQmlListReference::<span class="name">canCount</span>() const</h3>
<p>如果可以查询list属性的元素计数，则返回true，否则返回false。如果引用无效则返回false。</p>
<p><b>请参考 </b><a href="qqmllistreference.html#count">count</a>()<span lang="zh-cn">。</span></p>
<!-- @@@canCount -->
<!-- $$$clear[overload1]$$$clear -->
<h3 class="fn" id="clear"><a name="clear"></a><span class="type">bool</span> QQmlListReference::<span class="name">clear</span>() const</h3>
<p>清空列表。如果操作成功则返回true，否则返回false。</p>
<p><b>请参考 </b><a href="qqmllistreference.html#canClear">canClear</a>()<span lang="zh-cn">。</span></p>
<!-- @@@clear -->
<!-- $$$count[overload1]$$$count -->
<h3 class="fn" id="count"><a name="count"></a><span class="type">int</span> QQmlListReference::<span class="name">count</span>() const</h3>
<p>返回列表中对象的数量，如果操作失败则返回0。</p>
<!-- @@@count -->
<!-- $$$isManipulable[overload1]$$$isManipulable -->
<h3 class="fn" id="isManipulable"><a name="isManipulable"></a><span class="type">bool</span> QQmlListReference::<span class="name">isManipulable</span>() const</h3>
<p>如果实现了<a href="qqmllistreference.html#at">at</a>()， <a href="qqmllistreference.html#count">count</a>()， <a href="qqmllistreference.html#append">append</a>()和<a href="qqmllistreference.html#clear">clear</a>()则返回true，以便您可以操作列表。</p>
<p><b>请参考 </b><a href="qqmllistreference.html#isReadable">isReadable</a>()<span lang="zh-cn">，</span> <a href="qqmllistreference.html#at">at</a>()<span lang="zh-cn">，</span> <a href="qqmllistreference.html#count">count</a>()<span lang="zh-cn">，</span> <a href="qqmllistreference.html#append">append</a>()<span lang="zh-cn">，</span>
<span lang="zh-cn">和 </span><a href="qqmllistreference.html#clear">clear</a>()<span lang="zh-cn">。</span></p>
<!-- @@@isManipulable -->
<!-- $$$isReadable[overload1]$$$isReadable -->
<h3 class="fn" id="isReadable"><a name="isReadable"></a><span class="type">bool</span> QQmlListReference::<span class="name">isReadable</span>() const</h3>
<p>如果实现了<a href="qqmllistreference.html#at">at</a>()和<a href="qqmllistreference.html#count">count</a>()则返回true，以便您可以访问元素。</p>
<p><b>请参考 </b><a href="qqmllistreference.html#isManipulable">isManipulable</a>()<span lang="zh-cn">，</span> <a href="qqmllistreference.html#at">at</a>()<span lang="zh-cn">，</span>
<span lang="zh-cn">和 </span><a href="qqmllistreference.html#count">count</a>()<span lang="zh-cn">。</span></p>
<!-- @@@isReadable -->
<!-- $$$isValid[overload1]$$$isValid -->
<h3 class="fn" id="isValid"><a name="isValid"></a><span class="type">bool</span> QQmlListReference::<span class="name">isValid</span>() const</h3>
<p>如果实例引用有效的列表属性，则返回true，否则返回false。</p>
<!-- @@@isValid -->
<!-- $$$listElementType[overload1]$$$listElementType -->
<h3 class="fn" id="listElementType"><a name="listElementType"></a>const <span class="type"><a href="../qtcore/qmetaobject.html">QMetaObject</a></span> *QQmlListReference::<span class="name">listElementType</span>() const</h3>
<p>返回list属性中存储的元素的<a href="../qtcore/qmetaobject.html">QMetaObject</a>，如果引用无效则返回<code>nullptr</code> 
。</p>
<p>可以提前使用<a href="../qtcore/qmetaobject.html">QMetaObject</a>来确定是否可以将给定的实例添加到列表中。</p>
<!-- @@@listElementType -->
<!-- $$$object[overload1]$$$object -->
<h3 class="fn" id="object"><a name="object"></a><span class="type"><a href="../qtcore/qobject.html">QObject</a></span> *QQmlListReference::<span class="name">object</span>() const</h3>
<p>返回列表属性的对象。如果引用无效，则返回nullptr。</p>
<!-- @@@object -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
